cd "C:\Users\jtrounstine\Dropbox\LEAP Project\Manuscripts\Race paper\PoliticalBehavior"

***Figure 2 - cognitive load, all voters
***Experiment 1
use "Experiment 1 Replication Data.dta", clear

***add ideology ratings from Pre-test #2
merge m:1 candName using  "photorate.dta", gen(_mphotorate)
merge m:1 candName using  "textrate.dta", gen(_mtextrate)

***interacted Model
regress VotedFor i.candRace##HiCog if Photo==1 , cl(turkid)
mat    coef = e(b)
mat    varr = vecdiag(e(V))
matmap varr se , m(sqrt(@))
mat    coef = coef' , se', coef'-1.96*se', coef'+1.96*se'
scalar R = rowsof(coef)-1
mat    coef = coef[1..R,1..4]
matrix resmat = nullmat(resmat)\ coef
matrix colnames resmat =  coefficient se l_ci u_ci
matlist resmat

***Experiment 1
use "Experiment 2 Replication Data.dta", clear

***add photo ideology ratings from Pre-test #2
merge m:1 doqc01 using  "photorate.dta", gen(_mphotorate)


regress VotedFor i.cand_race2##atlarge if electiontype==1 , cl(turkid)
mat    coef = e(b)
mat    varr = vecdiag(e(V))
matmap varr se , m(sqrt(@))
mat    coef = coef' , se', coef'-1.96*se', coef'+1.96*se'
scalar R = rowsof(coef)-1
mat    coef = coef[1..R,1..4]
matrix resmat = nullmat(resmat)\ coef
matrix colnames resmat =  coefficient se l_ci u_ci
matlist resmat

svmat resmat , names(col) 
gen beta = 1 in 1
replace beta=[_n-1]+1 in 2/28
label define beta 1 "" 2 "Black_ELowCog" 3 "Asian_ELowCog" 4 "Hispanic_ELowCog" 5 "" 6 "White_EHiCog" 7 "" 8 "" 9 "" 10 "Black_EHiCog" 11"" 12 "Asian_EHiCog" 13"" 14 "Hispanic_EHiCog" 15 "" 16 "Black_ILowCog" 17 "Asian_ILowCog" 18 "Hispanic_ILowCog" 19 "" 20 "White_IHiCog" 21 "" 22 "" 23 "" 24 "Black_IHiCog" 25"" 26 "Asian_IHiCog" 27"" 28 "Hispanic_IHiCog", modify
label val beta beta 

generate candtype = 2 in 2
replace candtype = 3 in 10
replace candtype = 5 in 16
replace candtype=6 in 24

label define candtype 2 "Low Cognitive Load" 3 "High Cognitive Load Difference" 5 "District Elections" 6 "At-Large Elections Difference", modify
label val candtype candtype
twoway rspike l_ci u_ci candtype, plotregion(color(white)) graphregion(color(white)) horizontal lwidth(medium) lcolor(black) xtitle("") xscale(range(-.2 .2)) xlabel(#10) xline(0, lwidth(medium) lp(dot) lc(black)) yaxis(1 2) ytitle("", axis(2)) ytitle("", axis (1)) ylabel(none, axis(1)) yscale(noline axis(1)) yscale( reverse noline axis(2)) ylabel(2 3 5 6, valuelabel axis(2) angle(horizontal) noticks) ||scatter candtype coefficient , legend(off) mcolor(black) msize(medsmall)

matrix drop resmat
drop beta coefficient se l_ci u_ci candtype


***Figure 3 - cognitive load affects political liberals, not political conservatives
use "Experiment 1 Replication Data.dta", clear

***add ideology ratings from Pre-test #2
merge m:1 candName using  "photorate.dta", gen(_mphotorate)
merge m:1 candName using  "textrate.dta", gen(_mtextrate)

regress VotedFor i.candRace if HiCog==0 & Photo==1 & political_liberal==1, cl(turkid)
mat    coef = e(b)
mat    varr = vecdiag(e(V))
matmap varr se , m(sqrt(@))
mat    coef = coef' , se', coef'-1.96*se', coef'+1.96*se'
scalar R = rowsof(coef)-1
mat    coef = coef[1..R,1..4]
matrix resmat = nullmat(resmat)\ coef
matrix colnames resmat =  coefficient se l_ci u_ci
matlist resmat

regress VotedFor i.candRace if HiCog==1 & Photo==1 & political_liberal==1, cl(turkid)
mat    coef = e(b)
mat    varr = vecdiag(e(V))
matmap varr se , m(sqrt(@))
mat    coef = coef' , se', coef'-1.96*se', coef'+1.96*se'
scalar R = rowsof(coef)-1
mat    coef = coef[1..R,1..4]
matrix resmat = nullmat(resmat)\ coef
matrix colnames resmat =  coefficient se l_ci u_ci
matlist resmat

regress VotedFor i.candRace if HiCog==0 & Photo==1 & political_liberal==0, cl(turkid)
mat    coef = e(b)
mat    varr = vecdiag(e(V))
matmap varr se , m(sqrt(@))
mat    coef = coef' , se', coef'-1.96*se', coef'+1.96*se'
scalar R = rowsof(coef)-1
mat    coef = coef[1..R,1..4]
matrix resmat = nullmat(resmat)\ coef
matrix colnames resmat =  coefficient se l_ci u_ci
matlist resmat

regress VotedFor i.candRace if HiCog==1 & Photo==1 & political_liberal==0, cl(turkid)
mat    coef = e(b)
mat    varr = vecdiag(e(V))
matmap varr se , m(sqrt(@))
mat    coef = coef' , se', coef'-1.96*se', coef'+1.96*se'
scalar R = rowsof(coef)-1
mat    coef = coef[1..R,1..4]
matrix resmat = nullmat(resmat)\ coef
matrix colnames resmat =  coefficient se l_ci u_ci
matlist resmat

**Experiment 2
use "Experiment 2 Replication Data.dta", clear

***add photo ideology ratings from Pre-test #2
merge m:1 doqc01 using  "photorate.dta", gen(_mphotorate)

regress VotedFor i.cand_race2 if atlarge==0 & electiontype==1 & political_liberal==1 , cl(turkid)
mat    coef = e(b)
mat    varr = vecdiag(e(V))
matmap varr se , m(sqrt(@))
mat    coef = coef' , se', coef'-1.96*se', coef'+1.96*se'
scalar R = rowsof(coef)-1
mat    coef = coef[1..R,1..4]
matrix resmat = nullmat(resmat)\ coef
matrix colnames resmat =  coefficient se l_ci u_ci
matlist resmat

regress VotedFor i.cand_race2 if atlarge==1 & electiontype==1 & political_liberal==1 , cl(turkid)
mat    coef = e(b)
mat    varr = vecdiag(e(V))
matmap varr se , m(sqrt(@))
mat    coef = coef' , se', coef'-1.96*se', coef'+1.96*se'
scalar R = rowsof(coef)-1
mat    coef = coef[1..R,1..4]
matrix resmat = nullmat(resmat)\ coef
matrix colnames resmat =  coefficient se l_ci u_ci
matlist resmat

regress VotedFor i.cand_race2 if atlarge==0 & electiontype==1 & political_liberal==0 , cl(turkid)
mat    coef = e(b)
mat    varr = vecdiag(e(V))
matmap varr se , m(sqrt(@))
mat    coef = coef' , se', coef'-1.96*se', coef'+1.96*se'
scalar R = rowsof(coef)-1
mat    coef = coef[1..R,1..4]
matrix resmat = nullmat(resmat)\ coef
matrix colnames resmat =  coefficient se l_ci u_ci
matlist resmat

regress VotedFor i.cand_race2 if atlarge==1 & electiontype==1 & political_liberal==0 , cl(turkid)
mat    coef = e(b)
mat    varr = vecdiag(e(V))
matmap varr se , m(sqrt(@))
mat    coef = coef' , se', coef'-1.96*se', coef'+1.96*se'
scalar R = rowsof(coef)-1
mat    coef = coef[1..R,1..4]
matrix resmat = nullmat(resmat)\ coef
matrix colnames resmat =  coefficient se l_ci u_ci
matlist resmat

svmat resmat , names(col) 
gen beta = 1 in 1
replace beta=[_n-1]+1 in 2/32

generate candtype = 2 in 2
replace candtype = 3 in 6
replace candtype = 4 in 10
replace candtype = 5 in 14
replace candtype = 6 in 18
replace candtype = 7 in 22
replace candtype = 8 in 26
replace candtype = 9 in 30

label define candtype 2 "No Eye Blink - Political Liberal" 3 "Eye Blink - Political Liberal"  4 "No Eye Blink - Political Conservative" 5 "Eye Blink - Political Conservative" 6 "District - Political Liberal" 7 "At-Large - Political Liberal"  8 "District - Political Conservative" 9 "At-Large - Political Conservative", modify
label val candtype candtype
twoway rspike l_ci u_ci candtype, plotregion(color(white)) graphregion(color(white)) horizontal lwidth(medium) lcolor(gs10) xtitle("") xscale(range(-.2 .2)) xlabel(#10) xline(0, lwidth(medium) lp(dot) lc(black)) yaxis(1 2) ytitle("", axis(2)) ytitle("", axis (1)) ylabel(none, axis(1)) yscale(noline axis(1)) yscale( reverse noline axis(2)) ylabel(2 3 4 5 6 7 8 9, valuelabel axis(2) angle(horizontal) noticks) ||scatter candtype coefficient , legend(off) mcolor(black) msize(medsmall)

matrix drop resmat
drop beta coefficient se l_ci u_ci candtype

***Analyzing council makeup
use "Experiment 2 Replication Data.dta", clear

gen prob1w=totfemcand/totcand
gen prob2w=(totfemcand-1)/(totcand-1)
replace prob2w=. if condition==1
gen prob3w=(totfemcand-2)/(totcand-2)

gen jprob2w=prob2w*prob1w
gen jprob3w=prob3w*jprob2w

gen votedforw= VotedFor* cand_gender2
 by turkid ConditionElection_2, sort: egen totfemvote=sum(votedforw)
 by turkid ConditionElection_2, sort: egen totvotes=sum(VotedFor)
gen votedWhite=VotedFor* CandidateWhite
gen votedBlack=VotedFor*CandidateBlack
gen votedAsian=VotedFor*CandidateAsian
gen votedHisp=VotedFor*CandidateHisp
by ID ConditionElection_2, sort: egen totvotedWhite=sum(votedWhite)
by ID ConditionElection_2, sort: egen totvotedBlack=sum(votedBlack)
by ID ConditionElection_2, sort: egen totvotedAsian=sum(votedAsian)
by ID ConditionElection_2, sort: egen totvotedHisp=sum(votedHisp)
gen voteshareWhite= totvotedWhite/ totalwhitecand
gen voteshareBlack= totvotedBlack/ totalblackcand
gen voteshareAsian= totvotedAsian/ totalasiancand
gen voteshareHisp= totvotedHisp/ totalhispcand

gen pctWhitecouncil= totvotedWhite/3 if condition==2
gen pctBlackcouncil= totvotedBlack/3 if condition==2
gen pctAsiancouncil= totvotedAsian/3 if condition==2
gen pctHispcouncil= totvotedHisp/3 if condition==2

replace pctWhitecouncil= totvotedWhite if condition==1
replace pctBlackcouncil= totvotedBlack if condition==1
replace pctAsiancouncil= totvotedAsian if condition==1
replace pctHispcouncil= totvotedHisp if condition==1

gen pctcandWhite= totalwhitecand/6 if condition==2
gen pctcandBlack= totalblackcand/6 if condition==2
gen pctcandAsian= totalasiancand/6 if condition==2
gen pctcandHisp= totalhispcand/6 if condition==2

replace pctcandWhite= totalwhitecand/2 if condition==1
replace pctcandBlack= totalblackcand/2 if condition==1
replace pctcandAsian= totalasiancand/2 if condition==1
replace pctcandHisp= totalhispcand/2 if condition==1

ttest pctBlackcouncil= pctcandBlack if electiontype==1 & district==1 & pctcandBlack>0 & political_liberal==1
ttest pctBlackcouncil= pctcandBlack if electiontype==1 & district==0 & pctcandBlack>0 & political_liberal==1

gen oneblackcand=1 if atlarge==1 & pctcandBlack>0 & pctcandBlack<.2
replace oneblackcand=1 if atlarge==0 & pctcandBlack==.5
regress VotedFor i.cand_race2##atlarge if electiontype==1 & political_liberal==1 & oneblack==1 , cl(turkid)

***Ideology Ratings for Pictures
use "photo_rate.dta", clear
 table ratePhoto01_race, c(mean rateC1_pic sd rateC1_pic count rateC1_pic )
 
 ***Appendix
use "icma_results_graph.dta"
twoway (bar  pct_blkcncl var6 if atlarge==0)(bar  pct_blkcncl  var6 if atlarge==1)(rcap lci uci var6), legend(row(1) order(1 "District" 2 "At-Large")) xlabel(.5 "Non Concurrent" 3.5 "Concurrent", noticks) xtitle ("""") ytitle("Mean % Black Council") graphregion(margin(medlarge) fcolor(white)) plotregion(color(white))

